import java.util.Random;
import java.util.Vector;

public class EnemyTank extends Tank implements Runnable{
    Vector<Bullet> bulletVector = new Vector<>();
    EnemyTank(int x, int y) {
        super(x, y);
        setType(1);
    }
    Random random=new Random();
    @Override
    public void run() {
        while(true){
            try{
                Thread.sleep(500);
            } catch(InterruptedException e){
                throw new RuntimeException(e);
            }
            switch(this.getDirection()){
                case 0:
                    up();
                    if(this.getY()<0){
                        down();
                        down();
                        this.setDirection(1);
                    }
                    break;
                case 1:
                    left();
                    if(this.getX()<0){
                        right();
                        right();
                        this.setDirection(2);
                    }
                    break;
                case 2:
                    right();
                    if(this.getX()>700-30){
                        left();
                        left();
                        this.setDirection(3);
                    }
                    break;
                case 3:
                    down();
                    if(this.getY()>500-30){
                        up();
                        up();
                        this.setDirection(0);
                    }
                    break;
            }
            int a=random.nextInt(10);
            if(a<2){
                this.setDirection((int)random.nextInt(4));
            }
        }
    }

}
